package com.luli.service.impl;

import com.luli.service.Singer;
import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;

import java.lang.reflect.Method;

/**
 * 陆离
 * 2024/10/10 19:03:16
 * 经纪人
 */
public class Agent implements InvocationHandler {
    private Singer singer;
    /**
     * 设置代理的经济人
     *
     * @param singer
     */
    public void setSinger(Singer singer) {
        this.singer = singer;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("---------------经纪人把把关--------------");
        Object returnObj = method.invoke(singer, args);
        System.out.println("---------------唱完了收收钱------------------------");
        return returnObj;
    }
    /**
     * 获取一个代理对象
     * @return
     */
    public Object getProxy(){
        return Proxy.newProxyInstance(this.getClass().getClassLoader(),
                new Class[]{Singer.class},this);
    }

}